package com.bigevent.bigevent.service.impl;

import com.bigevent.bigevent.entity.Category;
import com.bigevent.bigevent.mapper.CategoryMapper;
import com.bigevent.bigevent.po.RegistCategoryPo;
import com.bigevent.bigevent.po.UpdateCategoryPo;
import com.bigevent.bigevent.service.CategoryService;
import com.bigevent.bigevent.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yangxudong
 * @description:
 * @date 2024/2/10 11:34
 */
@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public void addCategory(RegistCategoryPo categoryPo) {
        Category category = new Category();
        category.setCategoryAlias(categoryPo.getCategoryAlias());
        category.setCategoryName(categoryPo.getCategoryName());
        category.setCreateUser(UserUtil.getUserId());
        category.setCreateTime(LocalDateTime.now());
        category.setUpdateTime(LocalDateTime.now());
        categoryMapper.save(category);
    }

    @Override
    public List<Category> getCategoryList() {
        return categoryMapper.getCategoryList(UserUtil.getUserId());
    }

    @Override
    public Category getCategoryDetail(Integer id) {
        return categoryMapper.getCategoryDetail(id);
    }

    @Override
    public void updateCategory(UpdateCategoryPo categoryPo) {
        categoryMapper.updateCategory(categoryPo.getId(), categoryPo.getCategoryName(), categoryPo.getCategoryAlias());
    }

    @Override
    public void deleteCategory(Integer id) {
        categoryMapper.deleteCategory(id);
    }
}
